<?php

class StatController extends Zend_Controller_Action {

    public function init() {
        if (!Zend_Auth::getInstance()->hasIdentity()) {
            $this->_redirect('/authentification/login');
        }
    }

    public function indexAction() {
        // action body
    }

    public function cumulvisiteurAction() {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = "select idVisiteur, mois,count(*) as nbFiches,sum(montantValide)as total
                  from ficheFrais
                  where idEtat='RB'
                  group by idVisiteur,mois
                  order by idVisiteur";
        $lesStats = $db->fetchAll($query);
        $this->view->lesStats = $lesStats;
        $this->view->setEscape('htmlentities');
        $this->view->setEncoding('ISO-8859-1');
    }

    public function cumulfraisAction() {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = "select idVisiteur,mois,
                  sum(case idFraisForfait when 'ETP' then quantite*montant end) as ETP,
                  sum(case idFraisForfait when 'KM' then quantite*montant end) as KM,
                  sum(case idFraisForfait when 'NUI' then quantite*montant end) as NUI,
                  sum(case idFraisForfait when 'REP' then quantite*montant end) as REP
                  from fraisforfait,lignefraisforfait
                  where fraisforfait.id=lignefraisforfait.idFraisForfait
                  group by idVisiteur,mois
                  order by idVisiteur,mois";
        $lesStats = $db->fetchAll($query);
        $this->view->lesStats = $lesStats;
        $this->view->setEscape('htmlentities');
        $this->view->setEncoding('ISO-8859-1');
    }

    /* public function listerAction() {
      $lesVisiteurs = new Application_Model_DbTable_Visiteur();
      $select = $lesVisiteurs->select();
      $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbTableSelect($select));
      $paginator->setItemCountPerPage(10);
      $currentPage = isset($_GET['page']) ? (int) htmlentities($_GET['page']) : 1;
      $paginator->setCurrentPageNumber($currentPage);

      $this->view->setEscape('htmlentities');
      $this->view->setEncoding('ISO-8859-1');
      $this->view->paginator = $paginator;
      } */
}
